/**
 * Created by fengling on 2016/5/10.
 */
var userid=getParameter('userid');
var token=getParameter('token');
$(function() {
    var container = $('#dpgd');
    $('.btnSummit',container).click(function(){
        var dpzs = $('input[name="dpzs"]:checked',container).val();//大盘走势
        var csgd = $('#csgd',container).val();//阐述观点
        if(csgd==null||csgd==''){
            showmessage('观点不能为空!');
            return;
        }
        $.ajax({
            type: "post",
            url: httpurl+"/mobile/staff/webtalk/submitDPGD",
            data:{userid:userid,dpzs:dpzs,sm:csgd,token:token},
            dataType: "jsonp",
            jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
            success: function(result){
                if(result['code']=='10001'){
                    showmessage('提交成功！');
                    getGDTJ();
                }else{
                    showmessage(result['note']);
                }
            },
            error: function(){
                showmessage('提交失败!');
            }
        });
    });


    function getGDTJ(){
        $.ajax({
            type: "post",
            url: httpurl+"/mobile/staff/webtalk/getGDTJ",
            data:{token:token,gszlid:''},
            dataType: "jsonp",
            jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
            success: function(result){
                if(result['code']=='10001'){
                    showmessage('提交成功！');
                    var infoDetails = result.infosDetails;
                    var KZ = parseInt(nvl(infoDetails[0].KZ,0));
                    var KP = parseInt(nvl(infoDetails[0].KP,0));
                    var KD = parseInt(nvl(infoDetails[0].KD,0));
                    var sum = KZ+KP+KD;
                    if(sum==0){sum=1;}
                    var KZBL = KZ/sum;
                    var KPBL = KP/sum;
                    var KDBL = KD/sum;
                    var data = [];
                    data.push(['看涨',KZBL]);
                    data.push(['看平',KPBL]);
                    data.push(['看跌',KDBL]);
                    createPieChart('bttj','申万宏源股市周论多空分布',data,'申万宏源股市周论多空分布');
                }else{
                    showmessage(result['note']);
                }
            },
            error: function(){
                showmessage('提交失败!');
            }
        });
    }

    function createPieChart (renderDiv, name, data, titleText) {
        $('#' + renderDiv).highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: titleText
            },
            credits: {
                enabled: false//关闭图表版权
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '{point.percentage:.2f}%'
                    },
                    showInLegend: true
                }

            },
            series: [
                {
                    type: 'pie',
                    name: name,
                    data: data
                }
            ]
        });
    }
})